<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>第四版排产（弃用）</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
		 .layui-table th {
		    text-align: center;
		  }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请选择时间" style="display: inline; width: 80%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>

<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="table2" lay-filter="tableList"></table>

<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  导入</i></button>
	</div>
</script>
 
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script type="text/javascript">

document.onkeydown = function(e){    
    var ev =document.all ? window.event : e;  
    if(ev.keyCode==13) { 
        $('.layui-btn').trigger("click");
		return false
    }  
  } 
	layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
		var laydate = layui.laydate;
	    var form = layui.form;
	    
		var $ = layui.jquery, active = {
			reload:function () {
				var searchTime = $("#searchTime").val();
				console.log(searchTime)
				table.reload('contenttable',{
					method:'get',
					where:{"years":searchTime}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/month/selectList.do'
		    ,toolbar: '#toolbar'
		    ,title: '排产单'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
				      {type: 'checkbox', fixed: 'left'},
				      {field:'id', title:'ID'},
				      {field:'planid', title:'开始时间'},
				      {field:'proce', title:'结束时间'},
				      {field:'datatime', title:'已有日期'},
				      {fixed:'right', title:'操作', toolbar: '#rowToolbar', width:230}
				    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
		table.render({
		    elem: '#table2'
		    ,url:'${pageContext.request.contextPath }/planDetail/getList.do'
		    ,title: '排产单明细'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
				      {field:'id', title:'ID'},
				      {field:'', title:'当日工作量统计值',colspan: 10},
				      {field:'', title:'0960T',colspan: 10, align:'center'},
				      {field:'', title:'0980T',colspan: 10, align:'center'},
				      {field:'', title:'1080C',colspan: 10, align:'center'},
				      {field:'', title:'1060B',colspan: 10, align:'center'}
				    ],
				    [ {field:'remark4', title:'膜丝烘干',width:100},
				      {field:'remark1', title:'膜丝缓存',width:140},
				      {field:'starttime', title:'膜芯制作',width:120},
				      {field:'endtime', title:'组件组装',width:120},
				      {field:'unit', title:'膜丝切割',width:100},
				      {field:'num', title:'浇铸端盖安装',width:100},
				      {field:'num', title:'组件吊装离心',width:100},
				      {field:'num', title:'浇铸端盖拆卸',width:100},
				      {field:'num', title:'组件欲固化缓存',width:100},
				      {field:'num', title:'组件切割',width:100},
				      
				      {field:'remark4', title:'膜丝烘干',width:100},
				      {field:'remark1', title:'膜丝缓存',width:140},
				      {field:'starttime', title:'膜芯制作',width:120},
				      {field:'endtime', title:'组件组装',width:120},
				      {field:'unit', title:'膜丝切割',width:100},
				      {field:'num', title:'浇铸端盖安装',width:100},
				      {field:'num', title:'组件吊装离心',width:100},
				      {field:'num', title:'浇铸端盖拆卸',width:100},
				      {field:'num', title:'组件欲固化缓存',width:100},
				      {field:'num', title:'组件切割',width:100},
				      
				      {field:'remark4', title:'膜丝烘干',width:100},
				      {field:'remark1', title:'膜丝缓存',width:140},
				      {field:'starttime', title:'膜芯制作',width:120},
				      {field:'endtime', title:'组件组装',width:120},
				      {field:'unit', title:'膜丝切割',width:100},
				      {field:'num', title:'浇铸端盖安装',width:100},
				      {field:'num', title:'组件吊装离心',width:100},
				      {field:'num', title:'浇铸端盖拆卸',width:100},
				      {field:'num', title:'组件欲固化缓存',width:100},
				      {field:'num', title:'组件切割',width:100},
				      
				      {field:'remark4', title:'膜丝烘干',width:100},
				      {field:'remark1', title:'膜丝缓存',width:140},
				      {field:'starttime', title:'膜芯制作',width:120},
				      {field:'endtime', title:'组件组装',width:120},
				      {field:'unit', title:'膜丝切割',width:100},
				      {field:'num', title:'浇铸端盖安装',width:100},
				      {field:'num', title:'组件吊装离心',width:100},
				      {field:'num', title:'浇铸端盖拆卸',width:100},
				      {field:'num', title:'组件欲固化缓存',width:100},
				      {field:'num', title:'组件切割',width:100},
				      
				      {field:'remark4', title:'膜丝烘干',width:100},
				      {field:'remark1', title:'膜丝缓存',width:140},
				      {field:'starttime', title:'膜芯制作',width:120},
				      {field:'endtime', title:'组件组装',width:120},
				      {field:'unit', title:'膜丝切割',width:100},
				      {field:'num', title:'浇铸端盖安装',width:100},
				      {field:'num', title:'组件吊装离心',width:100},
				      {field:'num', title:'浇铸端盖拆卸',width:100},
				      {field:'num', title:'组件欲固化缓存',width:100},
				      {field:'num', title:'组件切割',width:100},
				    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
	//头工具栏事件
	table.on('toolbar(tableList)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					type: 1 					//Page层类型
			  		,area: ['700px', '600px'] 	//宽  高
			  		,title: '新增'
			  		,shade: 0.6 				//遮罩透明度
			  		,maxmin: true 				//允许全屏最小化
			  		,anim: 1 					//0-6的动画形式，-1不开启
			  		,content: $("#addDivID")
			  		,end: function(){
			  			$("#addDivID").hide();
			  		} 
				});
	      	break;
	    	case 'delete':
	        	var data = checkStatus.data;
	        	var idArr = new Array();
	        	if(data.length==0){
	        		toastr.warning("请至少选择一条记录！");
	        	}else {
	        		var ids = "";
		        	for(var i=0;i<data.length;i++){
		        		 if(i != data.length-1) {
			        	 	ids +=data[i].id+",";
			        	 }else {
			        	 	ids +=data[i].id;
			        	 }
		        	}
		        	layer.confirm('确定删除吗？', function(index){
				        $.ajax({
					    	type:'post',
					    	url:'${pageContext.request.contextPath }/month/delete.do',
					    	data:{"ids":ids},
					    	success:function(data){
					    		if(data > 0){
					    			toastr.success("删除成功！");
					    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
										window.location.reload();  
									},2000);
					    		}else{
					    			toastr.warning("删除失败！");
					    		}
					    	}
					    })
		        	})
	        	}
	      	break;
	      	case 'select':
	      		console.log(obj)
	      	break;
	    };
	});
  
	//监听行工具事件
	table.on('tool(tableList)', function(obj){
		var data = obj.data;
		console.log(obj)
		if(obj.event === 'del'){
		  layer.confirm('确定删除吗？', function(index){
		    var id = obj.data.id;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/month/delete.do',
		    	data:{"ids":id},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		}else if(obj.event === 'edit'){
			layer.open({
				  type: 1 		//Page层类型
				  ,area: ['500px', '450px'] //宽  高
				  ,title: '修改编辑'
				  ,shade: 0.6 	//遮罩透明度
				  ,maxmin: true //允许全屏最小化
				  ,anim: 1 		//0-6的动画形式，-1不开启
				  ,content:$("#editDivID")
				  ,success: function () {
					//回显表单数据
					for(var i=0;i<Object.entries(data).length;i++) {
						var id = '#' + Object.entries(data)[i][0];
						var text = Object.entries(data)[i][1];
						$(id).val(text);
					}
				  }	
				  ,end: function(){
			  			$("#editDivID").hide();
			  		} 
			});
		}
	});
	
	table.on('tool(planList)', function(obj){
		var data = obj.data;
		console.log(obj)
		if(obj.event === 'back'){
			
		    //var id = obj.data.id;
		    $("#planid").val(obj.data.remark4); 
		    $("#pnumber").val(obj.data.remark1); 
		    $("#pnum").val(obj.data.num); 
		    
		    if($("#pnum").val() != null ) {
		    	layer.close(index); 
		    }
		    
		}
	});
	
	
	/**
     * 表单校验
     */
    form.verify({
    	//value：表单的值、item：表单的DOM对象
    	email: function(value, item){
    		if(value == ''){
    			return '不能为空';
    		}
    	}
    });
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addForm)', function (data) {
      var datas=data.field;
   	  var action=data.form.action;
   	  $.ajax({
   		  url:action,
   		  data:datas,
   		  type:"POST",
   		  dataType:"json",
   		  success:function(result){
   			 if(result > 0) {
   				toastr.success("添加成功！");
   				$("#reset").click();
   				setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();  
				},2000);
   			 }else {
   				 toastr.warning("添加失败！");
   				 return false;
   			 }
   		  },
   	  });
   	  
   	  return false;
    });
    
    
    form.on('submit(detailForm)', function (data) {
      var datas=data.field;
   	  var action=data.form.action;
   	  $.ajax({
   		  url:"${pageContext.request.contextPath}/monthDetail/create.do",
   		  data:datas,
   		  type:"POST",
   		  dataType:"json",
   		  success:function(result){
   			 if(result > 0) {
   				toastr.success("添加成功！");
   				$("#reset").click();
   				setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.reload();  
				},2000);
   			 }else {
   				 toastr.warning("添加失败！");
   				 return false;
   			 }
   		  },
   	  });
   	  
   	  return false;
    });
    
    /**
     * 通用表单提交(AJAX方式)
     */
    form.on('submit(subform)', function (data) {
    	$.ajax({
			url : '${pageContext.request.contextPath}/month/edit.do',
			data: data.field,
			data : new FormData($('#formID')[0]),
			cache : false,
			type : "post",
			dataType : "json",
			processData : false,
			contentType : false,
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('修改成功！');
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							window.location.reload();  
						},2000);
					}
					$("#reset").click();
				}
			).fail(
				function(res) {
					toastr.error('修改失败！');
				}
			)
			return false;
    });
    
    
    form.on('submit(editform)', function (data) {
    	$.ajax({
			url : '${pageContext.request.contextPath}/monthDetail/edit.do',
			data: data.field,
			data : new FormData($('#editformID')[0]),
			cache : false,
			type : "post",
			dataType : "json",
			processData : false,
			contentType : false,
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('修改成功！');
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							window.location.reload();  
						},2000);
					}
					$("#reset").click();
				}
			).fail(
				function(res) {
					toastr.error('修改失败！');
				}
			)
			return false;
    });
    
  //时间检索
    laydate.render({
      elem: '#searchTime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime2',
      format: 'yyyy-MM-dd'
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

</body>
</html>